<?php

require_once 'classes/Employees.class.php';
require_once 'classes/EmployeeTypes.class.php';
require_once 'classes/Departments.class.php';

$objEmployees 	= new Employees();
$arrobjEmployees	= $objEmployees->fetchAllEmployees();
$objEmployeeTypes 	        = new EmployeeTypes();
$objDepartments 	    = new Departments();

// display( $arrobjPatients ); exit;

if( false == valArr( $arrobjEmployees ) ) {
	echo '<h2>Employees are not avaliable.</h2>';
} else {
?>
<link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="js/bootstrap-confirmation.js" type="text/javascript"></script>
<script>
	$(document).ready(function() {
		$('#dataTables-example').dataTable();
	});
</script>
<script>
function DeleteData(id){
               var r = confirm("Are You Sure Delete This Employee?");
               if (r==true){
                  $.ajax({
                     type: "POST",
                     url: "modules.php?file=delete_employees",
                     data:{did:id},
                     beforeSend : function () {
                     },
                     success:function(){
					 location.reload();
                     }
                  });
               }else{   
               }
            }
</script>
<style>
	.thclass{
	font-size:12px;
	}
	.tbclass{
	font-size:12px;
	}
</style>

<div style="margin-left:12px; margin-top: 10px;">
	<p>
		<a class="btn btn-outline btn-primary btn-xs" id="act" href="modules.php?file=employees&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >Add New Employees</a>
		<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_employees&type=view&mid=<? echo $mid;?>&smid=<? echo $smid;?>" >View All Employees</a>&nbsp;
	</p>
</div>
	
<div class="col-lg-12">
	<div class="panel panel-primary">
		
		<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>Charges List</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover" id="dataTables-example">
					<thead class="thclass">
						<tr>
							<th>Sr.No</th>
							<th>Empployee Name</th>
							<th>Employee Type</th>
							<th>Department</th>
							<th>Mobile</th>
							<th>Email</th>
							<th>Edit</th>
							<th>Delete</th>
					</thead>
					<tbody class="tbclass">
					<?php 
					$intSnCount = 0;
					foreach( $arrobjEmployees as $objEmployee ) {
						$intSnCount++;
						$arrobjEmployeeTypes 	= $objEmployeeTypes->fetchEmployeeTypesById($objEmployee->getEmployeeTypeId());
						$arrobjDepartments 	= $objDepartments->fetchDepartmentsById($objEmployee->getDepartmentId());
						
					?>
							<tr class="odd gradeX">
							<td><?  echo $intSnCount; ?></td>
							<td><? echo $objEmployee->getFirstName(); ?>&nbsp;<? echo $objEmployee->getLastName(); ?></td>
							<td><? echo $arrobjEmployeeTypes->getName(); ?></td>
							<td><? echo $arrobjDepartments->getName(); ?></td>
							<td><? echo $objEmployee->getMobileNumber(); ?></td>
							<td><? echo $objEmployee->getEmailAddress(); ?></td>
							<td>
								<a href="modules.php?file=employees&employee_id=<? echo $objEmployee->getId(); ?>&mid=<? echo $mid;?>&smid=<? echo $smid;?>" title="Update patient information"><img src="images/icons/update.png" width="25" height="25"></a>
							</td>
							<td>
								<a id="delete_employee" onClick="DeleteData(<?echo $objEmployee->getId();?>);"><img src="images/icons/delete.jpg" width="25" height="25"></a>
							</td>
							</tr>
					<?
					} 
					?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<?php
}
?>